<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>中心领导管理的操作页面</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../res/layui/layui.js"></script>
    <script src="../../res/js/Tools.js"></script>
</head>
<body>
<form class="layui-form" action="" id="Leader">
    <input type="hidden" name="expertId" id="expertIds"/>
    <div class="layui-form-item"></div>
    <div class="layui-form-item">
        <label class="layui-form-label">专家名称</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="expertName" id="expertNames" required
                   lay-verify="required" placeholder="专家名称" autocomplete="off"/>
        </div>
        <label class="layui-form-label">部门名称</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="deptName" id="deptNames" required
                   lay-verify="required" placeholder="部门名称" autocomplete="off"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">岗位名称</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="postName" id="postNames" required
                   lay-verify="required" placeholder="岗位名称" autocomplete="off"/>
        </div>
        <label class="layui-form-label">所在单位</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="oranName" id="oranNames" required
                   lay-verify="required" placeholder="所在单位(公司)" autocomplete="off"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">擅长说明</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="expertExp" id="expertExps" required
                   lay-verify="required" placeholder="擅长说明" autocomplete="off"/>
        </div>
        <label class="layui-form-label">专业</label>
        <div class="layui-input-inline">
            <select name="expertSpecia" id="expertSpecias" lay-verify="required" lay-filter="culture">
                <option value="" selected=""></option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系方式</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="phone" id="phones" required
                   lay-verify="required" placeholder="职责说明" autocomplete="off"/>
        </div>
        <label class="layui-form-label">通讯地址</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="addr" id="addrs" required
                   lay-verify="required" placeholder="通讯地址" autocomplete="off"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">其他说明</label>
        <div class="layui-input-inline">
            <input class="layui-input" type="text" name="other" id="others" required
                   lay-verify="required" placeholder="其他说明" autocomplete="off"/>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn site-demo-active" lay-submit lay-filter="formDemo" >立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form', 'layedit', 'laydate'], function() {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        //日期渲染
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });
        /**
         * 新增和修改
         */
        var form = null ;
        layui.use('form', function(){
            form = layui.form;
            //监听提交
            form.on('submit(formDemo)', function(data){
                // 单击之后提交按钮不可选,防止重复提交
                var DISABLED = 'layui-btn-disabled';
                // 增加样式
                $('.site-demo-active').addClass(DISABLED);
                // 增加属性
                $('.site-demo-active').attr('disabled', 'disabled');
                var rolesId = "";
                $("input[name='expertId']:checked").each(function(index,item){

                    rolesId+=$(this).val()+",";

                });
                data.field.leaderId=rolesId;

                //alert($("#leaderId").val()+"==============");
                var formData = new FormData(document.getElementById("Leader"));
                var url = "../../UserseControllerExpert/UpdateAndAdd";
                $.ajax({
                    url:url,
                    type:"post",
                    data:formData,
                    processData:false,
                    contentType:false,
                    dataType:"json",
                    success:function(obj){
                        //alert("成功了");
                        layer.msg(obj.msg, {
                            icon: 1,
                            time: 1000 //1秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            //关闭当前层
                            //当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            //刷新父页面
                            parent.tableTwo.reload();
                            /*if(data.isva == 1){
                                $("#isva").prop("checked",true);
                            }*/
                            //重新渲染
                            form.render();
                        });
                    },
                    error:function(e){
                        layer.msg("操作错误!");
                    }
                });
                return false;
            });
            //训练项目
            $.ajax({
                type:"POST",
                url:'../../UserseControllerExpert/findBaseSportName',  //从数据库查询返回的是个list
                dataType: "json",
                contentType: false,
                async: false,
                cache: false,
                success: function (data) {
                    $.each(data,function(index,item){
                        /*$('#sprotNames').append(new Option(item.sportName, item.sportId));*///往下拉菜单里添加元素
                        //$('#expertSpecias').append(new Option(item.sportName));
                        $('#expertSpecias' ). append("<option value='"+item.sportId+"'>"+item.sportName+"</option>")
                    })
                    form.render();//菜单渲染 把内容加载进去
                }
            })
            var id = getQueryString("id");
            if(id !="" && id != null){
                findlx(id);
            }
        });
        /**
         * 修改显示
         */
        function findlx(){
            var id = getQueryString("id");
            //alert(id);
            if(id){
                var url = "../../UserseControllerExpert/select";
                var data = {expertId:id};
                //jquery的ajax方法,查询类型的方法

                $.get(url,data,function(obj){
                    //从后台传过来的数据obj$("[value='11']").prop("checked",true);
                    $("#expertIds").val(obj.expertId);
                    $("#expertNames").val(obj.expertName);
                    $("#deptNames").val(obj.deptName);
                    $("#postNames").val(obj.postName);
                    $("#oranNames").val(obj.oranName);
                    $("#expertExps").val(obj.expertExp);
                    $("#expertSpecias").val(obj.expertSpecia);
                    $("#phones").val(obj.phone);
                    $("#addrs").val(obj.addr);
                    $("#others").val(obj.other);
                    //重新渲染
                    form.render();
                },"json");
            }
        }
    });
</script>
</body>
</html>